package com.yl.plugin.method;

import com.yl.plugin.method.base.BaseMethod;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.JavaVisibility;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;

/**
 * @author liuxubo
 */
public class UpdateMethod implements BaseMethod {

    @Override
    public int order() {
        return 5;
    }


    @Override
    public Method buildMethod(IntrospectedTable introspectedTable) {
        JavaVisibility methodVisibility = JavaVisibility.PUBLIC;

        FullyQualifiedJavaType methodReturnType = new FullyQualifiedJavaType("int");

        FullyQualifiedJavaType fullyQualifiedJavaType = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
        Parameter methodParameter = new Parameter(fullyQualifiedJavaType, StringUtils.uncapitalize(fullyQualifiedJavaType.getShortName()));

        Method method = new Method("update");
        method.setVisibility(methodVisibility);
        method.setReturnType(methodReturnType);
        method.addParameter(methodParameter);

        // 设置备注
        method.addJavaDocLine("/**");
        method.addJavaDocLine(" * 修改");
        method.addJavaDocLine(" * ");
        method.addJavaDocLine(" * @param " + methodParameter.getName());
        method.addJavaDocLine(" */");

        return method;
    }

}
